<?php
/**
 * This controller is uses to proccess course
 *
 * @author	huytbt
 * @date	2012-06-02
 * @version	1.0
 */
class CourseController extends HController
{
	/**
	 * This action is used to suggest courses for department
	 */
	public function actionSuggestCourses()
	{
		if (Yii::app()->request->isAjaxRequest && isset($_GET['q']) && isset($_GET['department_id'])) {
			$query = $_GET['q'];
			$department_id = $_GET['department_id'];
			Yii::import('application.modules.textbooks.models.TextbookCourse');
			$criteria = new CDbCriteria;
			$criteria->addSearchCondition('name', $query);
			$criteria->compare('department_id', $department_id);
			$courses = TextbookCourse::model()->findAll($criteria);
			$returnVal = ''; // return format using jQuery Autocomplete
			foreach ($courses as $course) {
				$returnVal .= $course->name . "\n";
			}
			echo $returnVal;
			Yii::app()->end();
		}
	}
}
